import { _decorator, Component, Material, MeshRenderer, Node, Vec3 } from 'cc';
import { constant } from '../framework/constant';
import { clientEvent } from '../framework/clientEvent';
import { monster } from './monster';
import { characterRigid } from './characterRigid';
import { monsterModel } from './monsterModel';
const { ccclass, property } = _decorator;

@ccclass('boss')
export class boss extends monster {

    @property(Node)
    /** 龙头  */
    public ndSocketDragonHead: Node = null!;

    @property(Material)
    /** 大龙默认材质 */
    public matDragon: Material = null!;

    @property(Material)
    /** 大龙受击后材质变白 */
    public matDragonHit: Material = null!;

    @property(MeshRenderer)
    public meshDragon: MeshRenderer = null!;

    /** 闪白倒计时 */
    private _countdown: number = 0.2;//
    /** 技能默认角度 */
    private _oriSkillEuler: Vec3 = new Vec3();
    /** 是否正在释放技能 */
    private _isSkillReleasing: boolean = false;

    onEnable() {
        clientEvent.on(constant.EVENT_TYPE.MONSTER_MOVE, this._monsterMove, this);
    }

    onDisable() {
        clientEvent.off(constant.EVENT_TYPE.MONSTER_MOVE, this._monsterMove, this);
    }
    public init(baseInfo: any, layerInfo: any) {
        this._bloodTipOffsetPos.set(0, 50, 0);
        this._hitEffectPos.set(0, 0.04, 0);

        this.baseInfo = baseInfo;
        this.layerInfo = layerInfo;
        this.isDie = false;

        this.scriptMonsterModel = this.node.getChildByName("body")?.getComponent(monsterModel) as monsterModel;
        this.scriptMonsterModel.playAni(constant.MONSTER_ANI_TYPE.IDLE, true);
        this.scriptCharacterRigid = this.node.getComponent(characterRigid) as characterRigid;

        this._isAllowToAttack = false;
        this._isSkillReleasing = false;
        this._countdown = 0.2;

        this.recycleWarning();
        this._refreshSkill();

        this.scriptMonsterModel.scriptMonster = this;

        this.curAttackSpeed = this.baseInfo.attackSpeed;
        this.curMoveSpeed = this.baseInfo.moveSpeed;

        this.meshDragon?.setMaterial(this.matDragon, 0);

        this._movePattern = layerInfo.movePattern ? layerInfo.movePattern : this.baseInfo.movePattern;

        super._getMinLength();
    }

    /**
     * 先移动
     *
     * @private
     * @memberof Monster
     */
    public _monsterMove() {
        super._monsterMove();
    }
}


